<%@tag description="Creates a form button that links to a URL" pageEncoding="UTF-8"%>
<%@ include file="/taglibs.jsp" %>

<%@ attribute name="url" required="false" description="URL for link." %>
<%@ attribute name="beanclass" required="false" description="Action class for link." %>
<%@ attribute name="value" required="false" description="Caption for the button." %>
<%@ attribute name="image" required="false" description="Image to use in lieu of a button." %>

<%@ variable name-given="_buttonLinkUrlProperties" variable-class="java.util.Map" scope="NESTED" %>

<%
jspContext.setAttribute("_buttonLinkUrlProperties", new java.util.LinkedHashMap(), PageContext.REQUEST_SCOPE);
%>

<jsp:doBody/>

<c:choose>
    <c:when test="${!empty url}">
        <s:url var="linkUrl" value="${url}">
            <c:forEach items="${_buttonLinkUrlProperties}" var="p">
                <s:param name="${p.key}" value="${p.value}"/>
            </c:forEach>
        </s:url>
    </c:when>
    <c:when test="${!empty beanclass}">
        <s:url var="linkUrl" beanclass="${beanclass}">
            <c:forEach items="${_buttonLinkUrlProperties}" var="p">
                <s:param name="${p.key}" value="${p.value}"/>
            </c:forEach>
        </s:url>
    </c:when>
</c:choose>

<c:if test="${!empty linkUrl}">
    <c:choose>
        <c:when test="${!empty image}">
            <a href="${linkUrl}"><img src="<%= request.getContextPath()%>${image}" border="0" alt="${value}"></a>
        </c:when>
        <c:otherwise>
            <input type="button" <c:if test="${!empty value}"> value="${value}" </c:if> onclick="parent.location='${linkUrl}';">
        </c:otherwise>
    </c:choose>
</c:if>
